package com.hxit.servics.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hxit.mapper.SystemLogsMapper;
import com.hxit.mapper.UserMapper;
import com.hxit.pojo.PageBean;
import com.hxit.pojo.SystemLogs;
import com.hxit.pojo.User;
import com.hxit.servics.SystemLogsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * @ClassName SystemLogsServiceImpl
 * @Author 12694
 * @Date 2024/11/4 21:34
 * @Version 1.0
 **/
@Service
@Transactional
public class SystemLogsServiceImpl implements SystemLogsService {
    private static final Logger log = LoggerFactory.getLogger(SystemLogsServiceImpl.class);
    @Autowired
    private SystemLogsMapper systemLogsMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public void insertSystemLogs(SystemLogs systemLogs) {
        User user = userMapper.FindById(systemLogs.getUserId());
        if (user != null){
            systemLogsMapper.insertSystemLogs(systemLogs);
        }else {
            log.error("插入失败，该用户的id不存在");
        }

    }
    @Override
    public PageBean selectSystemLogsPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<SystemLogs> empList = systemLogsMapper.selectSystemLogsPage();
        Page<SystemLogs> p= (Page<SystemLogs>) empList;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;

    }

    @Override
    public SystemLogs selectSystemLogsById(Integer id) {
        return systemLogsMapper.selectSystemLogsById(id);
    }

    @Override
    public void updateSystemLogs(SystemLogs systemLogs) {
        User user = userMapper.FindById(systemLogs.getUserId());
        if (user != null){
            systemLogsMapper.updateSystemLogs(systemLogs);
        }else {
            log.error("更新失败，该用户的id不存在");
        }

    }

    @Override
    public void deleteSystemLogs(List<Integer> ids) {
        systemLogsMapper.deleteSystemLogs(ids);
    }
}
